<template>
	<view class="content">
		<view class="top">
			<view class="box">
				<view class="avatar">
					<u-avatar class="avatar-item" :src="avatar" size="80"
						style="border: 1rpx solid #ff5500;"></u-avatar>
						<view class="tips-box">{{logo_title}}</view>
				</view>
				<view class="form">
					<view class="item">
						<view class="label" @click="focusShow('mobile')">
							<text class="icon-shouji iconfont" style="font-size: 40rpx;"></text>
							<text class="label-text">手机号</text>
						</view>
						<view class="input">
							<u-input placeholder="请输入..." fontSize="20" placeholder-style="color:red;font-size:40rpx" border="none" clearable :maxlength="11" :focus="focusForm.mobile"
								v-model="retrieveForm.mobile"></u-input>
						</view>
					</view>
					<view class="item" style="padding-bottom:0;">
						<view class="label" style="display: flex;" @click="focusShow('code')">
							<text class="icon-anquan iconfont" style="font-size: 40rpx;"></text>
							<text class="label-text">验证码</text>
						</view>
						<view class="input">
							<u-input placeholder="请输入..." :focus="focusForm.code" fontSize="20" placeholder-style="color:red;font-size:40rpx"  border="none" clearable v-model="retrieveForm.code">
								<template slot="suffix">
									<view>
										<u-code ref="uCode" @change="codeChange" changeText="X秒重新获取"
											seconds="60"></u-code>
										<u-button @tap="getCode" :text="tips" :color="tips=='获取验证码'?'#ff5500':'#d8d8d8'"></u-button>
									</view>
								</template>
							</u-input>
						</view>
					</view>
					<view class="item">
						<view class="label" style="display: flex;" @click="focusShow('password')">
							<text class="icon-jiesuo iconfont" style="font-size: 40rpx;"></text>
							<text class="label-text">密码</text>
						</view>
						<view class="input">
							<u--input placeholder="请输入..."  fontSize="20" placeholder-style="color:red;font-size:40rpx"  border="none" clearable password :focus="focusForm.password"
								v-model="retrieveForm.password"></u--input>
						</view>
					</view>
					<view class="item">
						<view class="label" style="display: flex;" @click="focusShow('ret_password')">
							<text class="icon-jiesuo iconfont" style="font-size: 40rpx;"></text>
							<text class="label-text">确认密码</text>
						</view>
						<view class="input">
							<u--input placeholder="请输入..."  fontSize="20" placeholder-style="color:red;font-size:40rpx"  border="none" clearable password  :focus="focusForm.ret_password"
								v-model="retrieveForm.ret_password"></u--input>
						</view>
					</view>

				</view>
				<view class="btn">
					<view class="registered">
						<view class="registered-btn" @click="retrieve">
							重置密码
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		checkMobile
	} from '@/utils/index.js'
	export default {
		data() {
			return {
				tips: '获取验证码',
				registeredChecked: false,
				retrieveForm: {
					mobile: '',
					password: '',
					code: '',
					ret_password: ''
				},
				settingData:{},
				avatar: '',
				logo_title: '',
				focusForm:{
					mobile: false,
					password:false,
					code: false,
					ret_password: false
				}
			}
		},
		onLoad() {
			this.settingData = uni.getStorageSync('settingData')
			this.avatar = this.settingData.image
			this.logo_title = this.settingData.value.logo_title
		},
		methods: {
			resetFocus(){
				this.focusForm={
					mobile: false,
					password:false,
					code: false,
					ret_password: false
				}
			},
			focusShow(type){
				this.resetFocus()
				if(type=='mobile'){
					this.focusForm.mobile = true
				}else if(type=="password"){
					this.focusForm.password = true
				}else if(type=="code"){
					this.focusForm.code = true
				}else if(type=="ret_password"){
					this.focusForm.ret_password = true
				}
			},
			codeChange(text) {
				this.tips = text;
			},
			getCode() {
				if (this.$refs.uCode.canGetCode) {
					// 模拟向后端请求验证码
					uni.showLoading({
						title: '正在获取验证码'
					})
					if (!this.retrieveForm.mobile) {
						uni.showToast({
							title: '请输入手机号',
							icon: 'none'
						});
						uni.hideLoading();
						return
					}
					if (!checkMobile(this.retrieveForm.mobile)) {
						uni.showToast({
							title: '请输入正确手机号',
							icon: 'none'
						});
						uni.hideLoading();
						return
					}
					this.$api.getRetrieveCode({
						mobile: this.retrieveForm.mobile
					}).then(res => {
						console.log(res);
						uni.hideLoading();
						// 这里此提示会被this.start()方法中的提示覆盖
						uni.$u.toast('验证码已发送');
						// 通知验证码组件内部开始倒计时
						this.$refs.uCode.start();
					})
				} else {
					uni.$u.toast('倒计时结束后再发送');
				}
			},
			retrieve() {
				if (!this.retrieveForm.mobile) {
					uni.showToast({
						title: '请输入手机号',
						icon: 'none'
					});
					return
				}
				if (!checkMobile(this.retrieveForm.mobile)) {
					uni.showToast({
						title: '请输入正确手机号',
						icon: 'none'
					});
					return
				}
				if (!this.retrieveForm.code) {
					uni.showToast({
						title: '请输入验证码',
						icon: 'none'
					});
					return
				}
				if (!this.retrieveForm.password) {
					uni.showToast({
						title: '请输入密码',
						icon: 'none'
					});
					return
				}
				if (this.retrieveForm.password.length < 6) {
					uni.showToast({
						title: '密码至少为六位',
						icon: 'none'
					});
					return
				}
				if (this.retrieveForm.ret_password !== this.retrieveForm.password) {
					uni.showToast({
						title: '两次密码不同',
						icon: 'none'
					});
					return
				}
				this.$api.memberretrieve(this.retrieveForm).then(res => {
					console.log(res);
					uni.navigateBack()
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.top {
		padding-top: 30rpx
	}

	.content {
		background: url('../../static/img/bg1.png') no-repeat;
		background-size: 100% 100%;
		min-height: 100vh;
		z-index: -1;

		.box {
			padding: 0 60rpx;
		}
	}

	.item {
		padding: 40rpx 0 20rpx;
		border-bottom: 1px solid #ff5500;
		.input{
			padding-top: 6rpx;
		}
	}

	.label {
		font-family: PingFangSC, PingFang SC;
		font-weight: 600;
		font-size: 40rpx;
		color: #111111;
		line-height: 40rpx;
		text-align: left;
		font-style: normal;
		padding-bottom: 10rpx;

		.label-text {
			padding-left: 20rpx;
			
		}
	}

	.btn {
		padding-top: 50rpx;

		.registered {
			display: flex;
			justify-content: center;

			.registered-btn {
				width: 630rpx;
				height: 84rpx;
				background: linear-gradient(270deg, #EA6F29 0%, #FAAA7D 100%);
				border-radius: 16rpx;
				line-height: 84rpx;
				text-align: center;
				font-family: PingFangSC, PingFang SC;
				font-size: 40rpx;
				font-weight: bold;
				color: #FFFFFF;
				font-style: normal;
			}
		}

		.forget {
			padding-top: 30rpx;
			display: flex;
			justify-content: center;

			.have {
				font-family: PingFangSC, PingFang SC;
				font-weight: 500;
				font-size: 36rpx;
				color: #111111;
				line-height: 40rpx;
				text-align: left;
				font-style: normal;
			}

			.login {
				font-family: PingFangSC, PingFang SC;
				font-weight: 500;
				font-size: 36rpx;
				color: #D06122;
				line-height: 40rpx;
				text-align: left;
				font-style: normal;
				border-bottom: 2rpx solid #D06122;
			}
		}
	}

	.agreement {
		padding-top: 60rpx;
		display: flex;
		justify-content: center;
		font-family: PingFangSC, PingFang SC;
		font-weight: 500;
		font-size: 20rpx;
		color: #999999;
		line-height: 60rpx;
		text-align: left;
		font-style: normal;
	}

	.blue {
		color: #347ced;
	}

	.prompt {
		width: 500rpx;
		height: 400rpx;
		background: white;
		border-radius: 15rpx;
		padding: 20rpx;

		.prompt-title {
			text-align: center;
		}

		.prompt-con {
			margin-top: 30rpx;
			padding: 10rpx;
			text-indent: 2em;
			font-family: PingFangSC, PingFang SC;
			font-weight: 600;
			font-size: 24rpx;
			font-style: normal;
		}

		.link {
			color: #2979ff;
			border-bottom: 1rpx solid #2979ff;
		}

		.prompt-ok {
			margin-top: 30rpx;
			padding: 10rpx;

			.prompt-btn {
				background: linear-gradient(270deg, #EA6F29 0%, #FAAA7D 100%);
				height: 70rpx;
				border-radius: 16rpx;
				font-family: PingFangSC, PingFang SC;
				font-weight: 500;
				font-size: 30rpx;
				color: #FFFFFF;
				line-height: 70rpx;
				text-align: center;
				font-style: normal;
			}
		}

		.prompt-on {
			padding: 10rpx;

			.prompt-btn {
				border: 1rpx solid #EA6F29;
				height: 70rpx;
				border-radius: 16rpx;
				font-family: PingFangSC, PingFang SC;
				font-weight: 500;
				font-size: 30rpx;
				color: #EA6F29;
				line-height: 70rpx;
				text-align: center;
				font-style: normal;
			}
		}
	}
	.avatar {
		padding-top: 100rpx;
	
		.avatar-item {
			margin: 0 auto;
		}
		.tips-box{
			font-size: 36rpx;
			font-weight: bold;
			color: #ed6d25;
			// background: linear-gradient(to right,#faa9a6,#eace2f,#D06122);
			// background-clip: text;
			// -webkit-background-clip: text;
			// -webkit-text-fill-color: transparent;
			margin-top: 30rpx;
			text-align: center;
		}
	}
</style>